'
' Copyright (c) 2004
' by Peter Donker ( info@bring2mind.net )
'
' Permission is hereby granted to use and/or modify this software for a single server. It is 
' NOT permitted to publish, distribute, sublicense, and/or sell copies of this software in its
' original or modified form. You are not allowed to remove this copyright notice. Please read the
' enclosed EULA for further details.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
' BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
' DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
'
Namespace Bring2mind.DNN.Modules.UserFiles
 Public Class ModuleSettings

  Private _MaxFileLength As Integer = 2000000
  Private _UserQuota As Integer = 5000000
  Private _MaxImageSize As Integer = 400
  Private _GridSize As Integer = 10
  Private _ValidExtensions As String = ".jpg;.bmp;.gif;.zip;"
  Private _UploadDirectory As String = ""
  Private _moduleId As Integer

  Friend Sub New(ByVal ModuleId As Integer)

   Dim ps As DotNetNuke.Entities.Portals.PortalSettings = DotNetNuke.Entities.Portals.PortalController.GetCurrentPortalSettings
   Dim mc As New DotNetNuke.Entities.Modules.ModuleController
   Dim ms As Hashtable = mc.GetModuleSettings(ModuleId)
   _moduleId = ModuleId

   'derived variables
   _UploadDirectory = ps.HomeDirectoryMapPath & "\UserFiles\"
   If Not IO.Directory.Exists(_UploadDirectory) Then
    IO.Directory.CreateDirectory(_UploadDirectory)
   End If

   If Not ms.Item("MaxFileLength") Is Nothing Then
    MaxFileLength = CType(ms.Item("MaxFileLength"), Integer)
   Else
    MaxFileLength = 2000000
   End If

   If Not ms.Item("UserQuota") Is Nothing Then
    UserQuota = CType(ms.Item("UserQuota"), Integer)
   Else
    UserQuota = 5000000
   End If

   If Not ms.Item("MaxImageSize") Is Nothing Then
    MaxImageSize = CType(ms.Item("MaxImageSize"), Integer)
   Else
    MaxImageSize = 400
   End If

   If Not ms.Item("GridSize") Is Nothing Then
    GridSize = CType(ms.Item("GridSize"), Integer)
   Else
    GridSize = 400
   End If

   If Not ms.Item("ValidExtensions") Is Nothing Then
    ValidExtensions = CType(ms.Item("ValidExtensions"), String)
   Else
    ValidExtensions = ".jpg;.bmp;.gif;.zip;"
   End If

  End Sub

  Friend Sub SaveSettings()

   Dim objModules As New DotNetNuke.Entities.Modules.ModuleController
   objModules.UpdateModuleSetting(_moduleId, "MaxFileLength", Me.MaxFileLength.ToString)
   objModules.UpdateModuleSetting(_moduleId, "UserQuota", Me.UserQuota.ToString)
   objModules.UpdateModuleSetting(_moduleId, "MaxImageSize", Me.MaxImageSize.ToString)
   objModules.UpdateModuleSetting(_moduleId, "GridSize", Me.GridSize.ToString)
   objModules.UpdateModuleSetting(_moduleId, "ValidExtensions", Me.ValidExtensions.ToString)

  End Sub

#Region "Properties"

  Friend Property MaxFileLength() As Integer
   Get
    Return _MaxFileLength
   End Get
   Set(ByVal Value As Integer)
    _MaxFileLength = Value
   End Set
  End Property

  Friend Property UserQuota() As Integer
   Get
    Return _UserQuota
   End Get
   Set(ByVal Value As Integer)
    _UserQuota = Value
   End Set
  End Property

  Friend Property MaxImageSize() As Integer
   Get
    Return _MaxImageSize
   End Get
   Set(ByVal Value As Integer)
    _MaxImageSize = Value
   End Set
  End Property

  Friend Property GridSize() As Integer
   Get
    Return _GridSize
   End Get
   Set(ByVal Value As Integer)
    _GridSize = Value
   End Set
  End Property

  Friend Property ValidExtensions() As String
   Get
    Return _ValidExtensions
   End Get
   Set(ByVal Value As String)
    _ValidExtensions = Value
   End Set
  End Property

  Friend ReadOnly Property UploadDirectory() As String
   Get
    Return _UploadDirectory
   End Get
  End Property

#End Region

 End Class

End Namespace